<?php 
require_once '../Generique/header_complet.php';
require_once "../Securite/parser_chaines.php";

$bdd = ouvrirBase();

if( isset( $_GET['numero'] ) && verifierChapitre( $bdd , $_GET['numero'] ) )
{
	$req = $bdd->prepare('SELECT * FROM dil_chapitres WHERE id = :id ');
	$req->bindValue('id', $_GET['numero'], PDO::PARAM_INT);
	$req->execute();
	$donnees = $req->fetch();
	
	$req4 = $bdd->prepare('SELECT * FROM dil_histoires WHERE dil_histoires.id = :id ');
	$req4->bindValue('id', $donnees['idHistoire'], PDO::PARAM_INT);
	$req4->execute();
	$donnees4 = $req4->fetch();
		
	if( isset( $_SESSION['nom'] ) && verifierModerateurUnivers($bdd, $donnees4['nomUnivers'] , $_SESSION['nom'] ) )
	{
		if( $donnees['autorise'] )
		{
			$nouveau = false;
		}
		else
		{
			$nouveau = true;
		}
		
		$req3 = $bdd->prepare('UPDATE dil_chapitres SET autorise = :droit WHERE id = :id ');
		$req3->bindValue('droit',$nouveau, PDO::PARAM_INT);
		$req3->bindValue('id', $_GET['numero'], PDO::PARAM_INT);
		$req3->execute();
	}
	echo '<script type="text/javascript">location.href = "chapitre.php?numero=' . $_GET['numero'] . '";</script>';
}
?>
